//
//  GAKKIBaseButton.m
//  GANGAIKit
//
//  Created by fh on 2019/11/6.
//  Copyright © 2019 cashchina. All rights reserved.
//

#import "GAKKIBaseButton.h"

@interface GAKKIBaseButton ()
@property (nonatomic, copy) void(^innerActionCallback)(GAKKIBaseButton *button);
@end

@implementation GAKKIBaseButton

- (void)dealloc {
    if (kDebugViewRelease) {
#ifdef DEBUG
        DBLog(@"\n ----------- 按钮 %@ 销毁了 ----------- \n",[self class]);
#endif
    }
}

+ (instancetype)initGAKKIBaseButton {
    GAKKIBaseButton *button = [GAKKIBaseButton new];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    button.backgroundColor = [UIColor whiteColor];
    return button;
}

+ (GAKKIBaseButton *)gakki_makeButton:(void (^)(GAKKIBaseButton * _Nonnull))block {
    GAKKIBaseButton *button = [GAKKIBaseButton initGAKKIBaseButton];
    if (block) {
        block(button);
    }
    return button;
}

+ (GAKKIBaseButton *)gakki_makeButton:(void (^)(GAKKIBaseButton * _Nonnull))block actionCallBack:(void (^)(GAKKIBaseButton * _Nonnull))actionCallBack {
    GAKKIBaseButton *button = [GAKKIBaseButton initGAKKIBaseButton];
    button.innerActionCallback = actionCallBack;
    [button addTarget:button action:@selector(innerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    if (block) {
        block(button);
    }
    return button;
}

- (GAKKIButtonFrame)gakki_frame {
    return ^(CGRect frame) {
        self.frame = frame;
        return self;
    };
}
- (GAKKIButtonBackgroundColor)gakki_backgroundColor {
    return ^(UIColor * __nullable backgroundColor) {
        self.backgroundColor = backgroundColor;
        return self;
    };
}
- (GAKKIButtonTitle)gakki_title {
    return ^(NSString * __nullable title, UIControlState state) {
        [self setTitle:title forState:state];
        return self;
    };
}
- (GAKKIButtonTitleColor)gakki_titleColor {
    return ^(UIColor * __nullable color, UIControlState state) {
        [self setTitleColor:color forState:state];
        return self;
    };
}
- (GAKKIButtonFont)gakki_font {
    return ^(UIFont * __nullable font) {
        self.titleLabel.font = font;
        return self;
    };
}
- (GAKKIButtonImage)gakki_image {
    return ^(UIImage * __nullable image, UIControlState state) {
        [self setImage:image forState:state];
        return self;
    };
}
- (GAKKIButtonBackgroundImage)gakki_backgroundImage {
    return ^(UIImage * __nullable image, UIControlState state) {
        [self setBackgroundImage:image forState:state];
        return self;
    };
}
- (GAKKIButtonTitleEdgeInsets)gakki_titleEdgeInsets {
    return ^(UIEdgeInsets titleEdgeInsets) {
        self.titleEdgeInsets = titleEdgeInsets;
        return self;
    };
}
- (GAKKIButtonImageEdgeInsets)gakki_imageEdgeInsets {
    return ^(UIEdgeInsets imageEdgeInsets) {
        self.imageEdgeInsets = imageEdgeInsets;
        return self;
    };
}

- (GAKKIButtonCornerRadius)gakki_cornerRadius {
    return ^(CGFloat cornerRadius) {
        self.layer.cornerRadius = cornerRadius;
        return self;
    };
}
- (GAKKIButtonBorderWidth)gakki_borderWidth {
    return ^(CGFloat borderWidth) {
        self.layer.borderWidth = borderWidth;
        return self;
    };
}
- (GAKKIButtonBorderColor)gakki_borderColor {
    return ^(UIColor *borderColor) {
        self.layer.borderColor = borderColor.CGColor;
        return self;
    };
}
- (GAKKIButtonClipsToBounds)gakki_clipsToBounds {
    return ^(BOOL clipsToBounds) {
        self.clipsToBounds = clipsToBounds;
        return self;
    };
}

#pragma mark - Event
- (void)innerButtonAction:(GAKKIBaseButton *)button {
    if (self.innerActionCallback) {
        self.innerActionCallback(button);
    }
}

@end
